package com.leyou.page.listener;

import com.leyou.common.constants.RocketMQConstants;
import com.leyou.page.service.PageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.leyou.common.constants.RocketMQConstants.CONSUMER.SECKILL_BEGIN_CONSUMER;
import static com.leyou.common.constants.RocketMQConstants.TAGS.SECKILL_BEGIN_TAGS;
import static com.leyou.common.constants.RocketMQConstants.TOPIC.SECKILL_TOPIC_NAME;

/**
 * 秒杀页面生成的监听器
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = SECKILL_BEGIN_CONSUMER,
        topic = SECKILL_TOPIC_NAME,
        selectorExpression = SECKILL_BEGIN_TAGS)
public class GenerateSecKillPageListener implements RocketMQListener<String> {

    @Autowired
    private PageService pageService;
    /**
     * 生成date日期的秒杀页面
     * @param date
     */
    @Override
    public void onMessage(String date) {

        log.info("【page服务】接收到秒杀创建页面消息，date:{}",date);
        pageService.createSecKillListAndDetailHtml(date);
    }
}
